/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Linking,
  Button
} from 'react-native';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

export default class App extends Component {

  _onButtonPress () {
    Linking.canOpenURL('myapp://').then(supported => {
      if (!supported) {
        alert('Can\'t handle url: ' + 'myapp://');
      } else {
        return Linking.openURL('myapp://');
      }
    }).catch(err => console.error('An error occurred', err));
  }

  // _onButtonPressWeibo () {
  //   Linking.canOpenURL('sinaweibo://detail?mblogid=4206370342998704').then(supported => {
  //     if (!supported) {
  //       alert('Can\'t handle url');
  //     } else {
  //       return Linking.openURL('sinaweibo://detail?mblogid=420637');
  //     }
  //   }).catch(err => console.error('An error occurred', err));
  // }

  // _onButtonPressWeixin () {
  //   Linking.canOpenURL('weixin://dl/profile').then(supported => {
  //     if (!supported) {
  //       alert('Can\'t handle url');
  //     } else {
  //       return Linking.openURL('weixin://dl/profile');
  //     }
  //   }).catch(err => console.error('An error occurred', err));
  // }

  _onButtonPressAppLinks () {
    Linking.canOpenURL('http://www.gongyz.cn').then(supported => {
      if (!supported) {
        alert('Can\'t handle url');
      } else {
        return Linking.openURL('http://www.gongyz.cn');
      }
    }).catch(err => console.error('An error occurred', err));
  }

    _onButtonPressUniversal () {
      Linking.canOpenURL('https://www.gongyz.cn').then(supported => {
        if (!supported) {
          alert('Can\'t handle url');
        } else {
          return Linking.openURL('https://www.gongyz.cn');
        }
      }).catch(err => console.error('An error occurred', err));
    
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
        <Button
          onPress={this._onButtonPress.bind(this)}
          title="Press Me"
        />

        {/* <Button
          onPress={this._onButtonPressWeibo.bind(this)}
          title="Press To Weibo"
        /> */}

        {/* <Button
          onPress={this._onButtonPressWeixin.bind(this)}
          title="Press To Weixin"
        /> */}

        {/* <Button
          onPress={this._onButtonPressAppLinks.bind(this)}
          title="Press Me to App Links"
        /> */}

        <Button
          onPress={this._onButtonPressUniversal.bind(this)}
          title="Press Me to Universal"
        />
      </View>

      
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
